<template>
  <div>
    <a-card title="提成账本">
      <a-form layout="inline" @submit.prevent>
        <a-form-item label="期间">
          <a-month-picker v-model:value="query.periodMonth" style="width: 160px" />
        </a-form-item>
        <a-form-item label="执行人">
          <a-input v-model:value="query.performerId" placeholder="用户ID" style="width: 180px" />
        </a-form-item>
        <a-form-item>
          <a-button type="primary" @click="fetchData">查询</a-button>
        </a-form-item>
      </a-form>

      <a-table :dataSource="list" :loading="loading" :pagination="pagination" rowKey="id" bordered>
        <a-table-column title="期间" dataIndex="periodMonth" />
        <a-table-column title="流程" dataIndex="workflowStepCode" />
        <a-table-column title="任务" dataIndex="taskCode" />
        <a-table-column title="执行人" dataIndex="performerId" />
        <a-table-column title="客户" dataIndex="customerId" />
        <a-table-column title="订单" dataIndex="orderId" />
        <a-table-column title="基数" dataIndex="amountBaseValue" />
        <a-table-column title="提成" dataIndex="amountCommission" />
        <a-table-column title="状态" dataIndex="status" />
        <a-table-column title="创建时间" dataIndex="createTime" />
      </a-table>
    </a-card>
  </div>
  </template>

<script setup>
import { ref, reactive } from 'vue';
import axios from 'axios';
import { getAppEnvConfig } from '/@/utils/env';
import { useUserStore } from '/@/store/modules/user';

const { VITE_GLOB_API_URL } = getAppEnvConfig();
const userStore = useUserStore();

const query = reactive({ periodMonth: '', performerId: '' });
const list = ref([]);
const loading = ref(false);
const pagination = reactive({ current: 1, pageSize: 10, total: 0, showSizeChanger: true, onChange: (p, s) => { pagination.current = p; pagination.pageSize = s; fetchData(); } });

async function fetchData() {
  loading.value = true;
  try {
    const params = { pageNo: pagination.current, pageSize: pagination.pageSize, ...query };
    const res = await axios.get(`${VITE_GLOB_API_URL}/hr/commission/ledger/list`, { params, headers: { 'X-Access-Token': userStore.getToken } });
    if (res.data && res.data.success) {
      list.value = res.data.result.records || [];
      pagination.total = res.data.result.total || 0;
    }
  } finally {
    loading.value = false;
  }
}

fetchData();
</script>

<style scoped>
</style>


